#include <STC15F2K60S2.H>
#include "Onewire.h"
#include "intrins.h"
#include "Relay.h"

#define WD_ZH 0X44  //温度转换指令
#define TG_ROM 0XCC  //跳过ROM
#define D_WD 0XBE  //读寄存器

void Delay1ms()		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	_nop_();
	_nop_();
	i = 11;
	j = 190;
	do
	{
		while (--j);
	} while (--i);
}


void DS18B20_Convert(void)
{
	Onewire_Init();
	Delay1ms();
	Write_Byte(TG_ROM);
	Write_Byte(WD_ZH);
}

float DS18B20_Read(void)
{
	unsigned char LSBT,MSBT;
	int Temp = 0;
	float b = 0;
	Onewire_Init();
	Delay1ms();
	Write_Byte(TG_ROM);
	Write_Byte(D_WD);
	LSBT = Read_Byte();
	MSBT = Read_Byte();
	Temp=(MSBT<<8)|LSBT;
	b = Temp/16.0;
	return b;
}

void Show_T()
{
	float T = 0;
	unsigned int t = 0;
	DS18B20_Convert();
	T = DS18B20_Read();
	t=(unsigned int)((T+0.05)*10);
	Nixie_Show(6,t/100);
	Nixie_Show(7,(t/10)%10+10);
	Nixie_Show(8,t%10);
	Latch_Init(0x80,~(t%10));
}


